<?php 
class db_game_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
	function test(){
		return "test1";                
               
    }
    
    //-------------------------------------------------------------------------
    //---------------------------- FOR GAME TABLE -----------------------------
    //-------------------------------------------------------------------------
    
    // get game
    function getAllGame(){
        $where=array("status"=>1);
        $query=$this->db
                ->select("gid,name,status,translocation,tellers")
                                ->where($where)
                ->get(PREFIX.'game');
        return $query->result();
    }
    // get game by game id
    function getGameByGID($gid='', $status=1){
        $where=array("status"=>$status,"gid"=>$gid);
        $query=$this->db
                ->select("gid,name,status,translocation,tellers")
                                ->where($where)
                ->get(PREFIX.'game');
        return $query->result();
    }
    //check game exist
    function isGameExist($gid=''){
        $where=array("gid"=>$gid,"status"=>1);
        $query=$this->db->where($where)->get(PREFIX."game");
        $count=$this->db->affected_rows();
        if($count>0) return true;
        return false;
    }
    
    //-------------------------------------------------------------------------
    //--------------------------- FOR SERVER TABLE ----------------------------
    //-------------------------------------------------------------------------
    
    // get server
    function getAllServer($gid=''){
        $where=array("status"=>1,"gid"=>$gid);
        $query=$this->db
                ->select("sid,name,status")
                                ->where($where)
                ->get(PREFIX.'server');
        return $query->result();
    }
    //check server exist
    function isServerExist($sid=''){
        $where=array("sid"=>$sid);
        $query=$this->db->where($where)->get(PREFIX."server");
        $count=$this->db->affected_rows();
        if($count>0) return true;
        return false;
    }
    // get game by server id
    function getServerBySID($sid='', $status=1){
        $where=array("status"=>$status,"sid"=>$sid);
        $query=$this->db
                ->select("gid,name,status")
                                ->where($where)
                ->get(PREFIX.'server');
        return $query->result();
    }
}
?>
